home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / hurd / fd-read.c < prev    next >
C/C++ Source or Header  |  1994-05-11  |  2KB  |  79 lines

  1. /* Copyright (C) 1993, 1994 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB.  If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.  */
  18.  
  19. #include <errno.h>
  20. #include <unistd.h>
  21. #include <hurd.h>
  22. #include <hurd/fd.h>
  23.  
  24. error_t
  25. _hurd_fd_read (struct hurd_fd *fd, void *buf, size_t *nbytes)
  26. {
  27.   error_t err;
  28.   char *data;
  29.   mach_msg_type_size_t nread;
  30.  
  31.   data = buf;
  32.   err = HURD_FD_PORT_USE
  33.     (fd,
  34.      ({
  35.      call:
  36.        err = __io_read (port, &data, &nread, -1, *nbytes);
  37.        if (ctty != MACH_PORT_NULL && err == EBACKGROUND)
  38.      {
  39. #if 1
  40.        abort ();
  41. #else
  42.        struct _hurd_sigstate *ss = _hurd_self_sigstate ();
  43.        if (_hurd_orphaned ||
  44.            __sigismember (SIGTTIN, &ss->blocked) ||
  45.            ss->actions[SIGTTIN].sa_handler == SIG_IGN)
  46.          {
  47.            /* We are orphaned, or are blocking or ignoring SIGTTIN.
  48.           Return EOF instead of stopping.  */
  49.            __mutex_unlock (&ss->lock);
  50.            nread = 0;
  51.            err = 0;
  52.          }
  53.        else
  54.          {
  55.            const int restart = ss->actions[SIGTTIN].sa_flags & SA_RESTART;
  56.            _hurd_raise_signal (ss, SIGTTIN, 0); /* Unlocks SS->lock.  */
  57.            if (restart)
  58.          goto call;
  59.            else
  60.          err = EINTR;    /* XXX Is this right? */
  61.          }
  62. #endif
  63.      }
  64.        err;
  65.      }));
  66.  
  67.   if (err)
  68.     return err;
  69.  
  70.   if (data != buf)
  71.     {
  72.       memcpy (buf, data, nread);
  73.       __vm_deallocate (__mach_task_self (), (vm_address_t) data, nread);
  74.     }
  75.  
  76.   *nbytes = nread;
  77.   return 0;
  78. }
  79.